<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="菜品名称" prop="dname">
        <el-input
          v-model="queryParams.dname"
          placeholder="请输入菜品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>

      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:dish2:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <!--    菜品图片循环-->
    <div class="zhongjian">
      <div class="kuai" v-for="dish in dish2List" :key="dish.dish2List">
        <div class="tupian" @click="getDish(dish)">
          <img :src="'http://localhost:8080' + dish.dimage"/>
        </div>
        <div class="cainame">
          <b>{{dish.dname}}</b>
        </div>

      </div>
      <!--菜品详情展示对话框-->
      <el-dialog
        title="菜品详情"
        :visible.sync="dialogVisible"
        width="30%">

        <span><img style="width: 100%;height: 100%" :src="'http://localhost:8080' + dish.dimage"/></span>

        <br>
        <b><span>菜名:{{dish.dname}}</span></b>
        <br>
        <b> 价格:<span style="color: skyblue">{{dish.dprice}}元</span></b>
        <br>
        <b><span>介绍:{{dish.dintrodoce}}</span></b>

      </el-dialog>

    </div>


    <!--分页-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import {listDish2, getDish2, delDish2, addDish2, updateDish2} from "@/api/project/dish2";

  export default {
    name: "Dish2",
    data() {
      return {
        text: '',
        //展示信息
        dish: {},
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 菜品图片信息展示表格数据
        dish2List: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          dname: null,
          /*did: null,*/
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        tupian: "",
        showContent: false,
        dialogVisible: false
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询菜品图片信息展示列表 */
      getList() {
        this.loading = true;
        listDish2(this.queryParams).then(response => {
          //打印菜品请求的信息
          console.log(response.rows);

          this.dish2List = response.rows;
          //打印下标为1的图片信息
          // console.log(this.dish2List[1].dimage);
          // this.images=this.dish2List[1].dimage;
          // this.cainame=this.dish2List[1].dname;

          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      //点击图片，查看详情
      getDish(dish) {
        this.dialogVisible = true;
        this.dish = dish;
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('project/dish2/export', {
          ...this.queryParams
        }, `dish2_${new Date().getTime()}.xlsx`)
      },

    }
  };
</script>

<style scoped>
  .zhongjian {
    margin-left: 10px;
    display: flex;
    flex-wrap: wrap; /* 允许项目换行 */
    /*justify-content: space-between; !* 项目之间的空间平均分配 *!*/
    position: relative;
  }

  .kuai {
    height: 250px;
    width: 200px;
    /*background-color: green;*/
    margin-top: 20px;
    margin-left: 20px;
    margin-right: 20px;

  }

  .tupian {
    height: 200px;
    width: 200px;
    /*border: 1px solid black;*/
  }

  img {
    height: 200px;
    width: 200px;
  }

  .cainame {
    line-height: 50px;
    text-align: center;
  }


</style>
